package service

import (
	"apitestAfterGo/dao"
	"apitestAfterGo/domain"
)

type testCaseService struct {
	GetAllTestCaseBySuiteId func(systemId, taskId, suiteId int) []domain.TestCase
	AddCase                 func(testCase domain.TestCase) domain.TestCase
	ModifyTestCase          func(testCase domain.TestCase) domain.TestCase
	GetTestCaseById         func(id int) domain.TestCase
	DeleteTestCaseById      func(id int) bool
}

var TestCaseServiceImpl testCaseService

func init() {
	TestCaseServiceImpl = testCaseService{
		GetAllTestCaseBySuiteId: func(systemId, taskId, suiteId int) []domain.TestCase {
			var testCases []domain.TestCase
			dao.GormDb.Debug().Where("system_id =? and task_id =? and task_suite_id = ?", systemId, taskId, suiteId).Find(&testCases)
			return testCases
		},
		AddCase: func(testCase domain.TestCase) domain.TestCase {
			dao.GormDb.Debug().Create(&testCase)
			return testCase
		},
		ModifyTestCase: func(testCase domain.TestCase) domain.TestCase {
			dao.GormDb.Debug().Model(&testCase).Updates(testCase)
			return testCase
		},
		GetTestCaseById: func(id int) domain.TestCase {
			var testCase domain.TestCase
			dao.GormDb.Debug().Where("id = ?", id).Find(&testCase)
			return testCase
		},
		DeleteTestCaseById: func(id int) bool {
			dao.GormDb.Debug().Where("id = ?", id).Delete(&domain.TestCase{})
			return true
		},
	}
}
